package com.tocici.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.tocici.domain.vo.CateStatVo;
import com.tocici.domain.vo.CategoryVo;
import com.tocici.domain.vo.UserStatVo;
import com.tocici.service.ICategoryService;
import com.tocici.service.IMusicService;
import com.tocici.service.IUserBehaviorService;
import com.tocici.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/music")
@SaIgnore
@RequiredArgsConstructor
public class MusicIndexController {
    private final IUserService userService;

    private final IMusicService musicService;

    private final ICategoryService categoryService;

    private final IUserBehaviorService userBehaviorService;



    @GetMapping("/index/userStat")
    public R<List<UserStatVo>> getUserStat(){
        List<UserStatVo> vos = userService.getUserStat();
        return R.ok(vos);
    }

    @GetMapping("/index/cateStat")
    public R<List<CateStatVo>> getCateStat(){
        List<CateStatVo> musicCates = musicService.getMusicCates();
        musicCates.forEach(music -> {
            Long categoryId = music.getCategoryId();
            CategoryVo categoryVo = categoryService.queryById(categoryId);
            music.setName(categoryVo.getCategoryName());
            List<Integer> values = music.getValues();
            values.add(music.getValue());
            music.setValues(values);
        });
        return R.ok(musicCates);

    }

    @GetMapping("/index/durationStat")
    public R<List<UserStatVo>> getDurationUserStat(){
        List<UserStatVo> durationStat = userBehaviorService.getDurationStat();
        return R.ok(durationStat);
    }

}
